//
//  IBDEmptyView.m
//  Merchant
//
//  Created by admin on 16/4/28.
//  Copyright © 2016年 ibendi. All rights reserved.
//

#import "IBDEmptyView.h"

@implementation IBDEmptyView
{
    UIImageView *_empImgView;
    UILabel *_textLbl;
    UILabel *_subLbl;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _empImgView = [[UIImageView alloc] init];
        _textLbl = [[UILabel alloc] init];
        _subLbl = [[UILabel alloc] init];
        
        [self addSubview:_empImgView];
        [self addSubview:_textLbl];
        [self addSubview:_subLbl];
        
        _textLbl.font =[UIFont fontWithName:@"AmericanTypewriter-Bold" size:20.f];
        [_textLbl setTextColor:[UIColor grayColor]];
        [_textLbl setBackgroundColor:[UIColor clearColor]];
        [_textLbl setTextAlignment:NSTextAlignmentCenter];
        
        
        _subLbl.font =[UIFont fontWithName:@"AmericanTypewriter-Bold" size:16.f];
        [_subLbl setTextColor:[UIColor grayColor]];
        [_subLbl setBackgroundColor:[UIColor clearColor]];
        [_subLbl setTextAlignment:NSTextAlignmentCenter];
        
        
        [_textLbl sizeToFit];
        [_subLbl sizeToFit];
        _textLbl.numberOfLines = 0;
        _subLbl.numberOfLines = 0;
    }
    
    return self;
}

-(void)setImage:(UIImage *)image andText:(NSString *)text andSubTex:(NSString *)subTex
{
    CGFloat ys  = 200;
    if (self.frame.size.height == 0) {
        ys = [UIScreen mainScreen].bounds.size.height/3;
    }else{
        ys = self.frame.size.height/3;
    }
    
    if (subTex != nil) {
        _subLbl.layer.borderWidth = 1;
        _subLbl.layer.borderColor = [UIColor grayColor].CGColor;
        _subLbl.layer.cornerRadius = 4;
    }

    if (image != nil) {
        _empImgView.sd_layout.centerXEqualToView(self).centerYIs(ys).widthIs(image.size.width).heightIs(image.size.height);
        _textLbl.sd_layout.topSpaceToView(_empImgView,15).leftSpaceToView(self,30).rightSpaceToView(self,30).autoHeightRatio(0);
//        _subLbl.sd_layout.topSpaceToView(_textLbl,5).leftSpaceToView(self,30).rightSpaceToView(self,30).autoHeightRatio(0);
        _subLbl.sd_layout.topSpaceToView(_textLbl,10).centerXEqualToView(self).widthIs(140).heightIs(35);
        _empImgView.image = image;
        
    }else{
        [_empImgView removeFromSuperview];
        _textLbl.sd_layout.centerYIs(ys).leftSpaceToView(self,30).rightSpaceToView(self,30).autoHeightRatio(0);
//        _subLbl.sd_layout.topSpaceToView(_textLbl,0).leftSpaceToView(self,30).rightSpaceToView(self,30).autoHeightRatio(0);
        _subLbl.sd_layout.topSpaceToView(_textLbl,10).centerXEqualToView(self).widthIs(140).heightIs(35);
    }
    _textLbl.text = text;
    _subLbl.text = subTex;
    
}

- (void) addEmptyAction:(void(^)(void))compy
{
    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];
    [singleTapGestureRecognizer setNumberOfTapsRequired:1];
    [self addGestureRecognizer:singleTapGestureRecognizer];
    self.emptyBKAction = [compy copy];
}
- (void)singleTap:(UIGestureRecognizer*)gestureRecognizer
{
    self.emptyBKAction();
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
